package com.tsk.state.test;

import org.springframework.statemachine.config.StateMachineFactory;
import org.springframework.statemachine.persist.StateMachinePersister;

import java.util.Objects;

/**
 * @author: 黄嘉振
 * @create: 2023/5/25 17:22
 * @description:
 **/
public class StatemachineServiceBuilder<S, E, T> {
    private StateMachinePersister<S, E, T> stateMachinePersist;
    private StateMachineFactory<S, E> stateMachineFactory;

    public StatemachineServiceBuilder<S, E, T>
    setStateMachinePersister(StateMachinePersister<S, E, T> stateMachinePersist) {
        this.stateMachinePersist = stateMachinePersist;
        return this;
    }

    public StatemachineServiceBuilder<S, E, T> setStateMachineFactory(StateMachineFactory<S, E> stateMachineFactory) {
        this.stateMachineFactory = stateMachineFactory;
        return this;
    }

    public StatemachineService<S, E, T> builder() {
        Objects.requireNonNull(stateMachineFactory, "stateMachineFactory 不能为空");
        Objects.requireNonNull(stateMachinePersist, "stateMachinePersist 不能");
        StatemachineService<S, E, T> service = new StatemachineService<>();
        service.setStateMachineFactory(stateMachineFactory);
        service.setSetStateMachinePersister(stateMachinePersist);
        return service;
    }
}
